package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;
import liumengbaio.lolzhangyoubao.Activity.Activity.FiendInfoActivity;
import liumengbaio.lolzhangyoubao.Activity.Activity.PersonInfoActivity;
import liumengbaio.lolzhangyoubao.Activity.InFo.FindFriendInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/15.
 */
public class FindFriendItemAdapter extends BaseAdapter {
    private Context mContext;
    private FindFriendInfo findFriendInfo;
    public FindFriendItemAdapter(Context mContext, FindFriendInfo findFriendInfo) {
        this.mContext = mContext;
        this.findFriendInfo = findFriendInfo;
    }

    @Override
    public int getCount() {
        return findFriendInfo.getData().size();
    }

    @Override
    public Object getItem(int position) {
        return findFriendInfo.getData().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        FindFriendViewHolder holder = null;
        if (holder == null) {
            holder = new FindFriendViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.find_friend_item, null);
            holder.head_icon = (CircleImageView) convertView.findViewById(R.id.head_icon);
            holder.tv_coment_item = (TextView) convertView.findViewById(R.id.tv_coment_item);
            holder.tv_nicker_name = (TextView) convertView.findViewById(R.id.tv_nicker_name);
            holder.tv_lol_name = (TextView) convertView.findViewById(R.id.tv_lol_name);
            holder.tv_do_black_voice = (TextView) convertView.findViewById(R.id.tv_do_black_voice);
            holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            holder.tv_in_the_city = (TextView) convertView.findViewById(R.id.tv_in_the_city);
            holder.tv_fight_notice = (TextView) convertView.findViewById(R.id.tv_fight_notice);
            holder.tv_good = (TextView) convertView.findViewById(R.id.tv_good);
            convertView.findViewById(R.id.head_icon).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String url="http://lol.zhangyoubao.com/apis/rest/UsersService/getOtherUserInfo?from_userid=&userid="+findFriendInfo.getData().get(position).getUser_id()+"&i_=Lf2he/rdpOPtR1PwqdUiuwS64wm6xMV8rBpebf4NEuI=&deviceId=Lf2he/rdpOPtR1PwqdUiuwS64wm6xMV8rBpebf4NEuI=&t_=1474002437348&p_=24389&v_=400902&a_=lol&pkg_=com.anzogame.lol&d_=android&osv_=17&cha=baiduMartket&u_=&modle_=vivo%20Y15T&api=UsersService.getOtherUserInfo&time=1474002300&game=lol&secretId=AKIDz8krbsJ5yKBZQpn74WFkmLPx3gnPhESA&secretVersion=v1.0&nonce=28564&secretSignature=e3JK4KLGbeMjeb18867V3KJgF7U=";
                    Intent intent_person_info=new Intent(mContext, FiendInfoActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("url",url);
                    intent_person_info.putExtras(bundle);
                    mContext.startActivity(intent_person_info);
                }
            });
            convertView.findViewById(R.id.to_person_info).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent_person_info=new Intent(mContext,PersonInfoActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("id",findFriendInfo.getData().get(position).getId());
                    intent_person_info.putExtras(bundle);
                    mContext.startActivity(intent_person_info);
                }
            });
            convertView.findViewById(R.id.person_info).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent_person_info=new Intent(mContext,PersonInfoActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("id",findFriendInfo.getData().get(position).getId());
                    intent_person_info.putExtras(bundle);
                    mContext.startActivity(intent_person_info);
                }
            });
        } else {
            holder = (FindFriendViewHolder) convertView.getTag();
        }
        Picasso.with(mContext).load(findFriendInfo.getData().get(position).getAvatar()).into(holder.head_icon);
        holder.tv_coment_item.setText(findFriendInfo.getData().get(position).getComment());
        holder.tv_do_black_voice.setText("开黑语音:"+"不确定");
        holder.tv_fight_notice.setText("约战宣言:"+findFriendInfo.getData().get(position).getSlogan());
        holder.tv_good.setText(findFriendInfo.getData().get(position).getGood());
        holder.tv_nicker_name.setText(findFriendInfo.getData().get(position).getNickname());
        holder.tv_time.setText(findFriendInfo.getData().get(position).getCreated());
        holder.tv_lol_name.setText(findFriendInfo.getData().get(position).getSummoner());
        return convertView;
    }

    private class FindFriendViewHolder {
        private CircleImageView head_icon;
        private TextView tv_nicker_name, tv_lol_name, tv_time, tv_do_black_voice, tv_in_the_city, tv_fight_notice,
                tv_good, tv_coment_item;
    }
}
